﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;

namespace DotNETX.Utility.Text
{
    public static class StringParseUtils
    {
        public static NameValueCollection ParseKeyValues(string str, string groupSplitter = ";", string kvSplitter="=")
        {
            NameValueCollection nvc = new NameValueCollection();
            if (str == null) return nvc;
            string[] groups = str.Split(new string[] { groupSplitter }, StringSplitOptions.RemoveEmptyEntries);
            if (groups == null || groups.Length == 0) return nvc;
            foreach (string group in groups)
            {
                string[] kv = group.Split(new string[] { kvSplitter }, StringSplitOptions.RemoveEmptyEntries);
                if (kv != null && kv.Length == 2)
                {
                    nvc.Add(kv[0], kv[1]);
                }
            }
            return nvc;
        }
    }
}
